(function(window){
    var appCtrl = { 
        bindEven: function(){
            var bindings = [{
               // element:document,
                element:'.item-image img',
                event: hiApp.device.click,
                handler: this.photoBrowser
            },
			{
                element:document,
                selector:'form.ajax-submit',
                event: 'submitted',
                handler: this.ajax_submit
            },
			{
                element:document,
                selector:'.upload_input',
                event: 'change',
                handler: this.upload_input
            },
			{
                element: '.play_mp3',
                event: hiApp.device.click,
                handler: this.play_mp3
            },
			{
                element: '.questchoice_1 dd',//单选
                event: hiApp.device.click,
                handler: this.questchoice_1
            },
			{
                element: '.questchoice_2_3 dd',//多选
                event: hiApp.device.click,
                handler: this.questchoice_2_3
            },
			/*{
                element: '.popover_button',
                event: hiApp.device.click,
                handler: this.popover
            },
			{
                element: '.popover_hover',
                event: "mouseover",
                handler: this.popover
            },*/
			{
                element: 'body',
                event: hiApp.device.click,
                handler: this.body_click
            }
			];
            bindEvents(bindings);
        },
		questchoice_2_3:function(){
			var data=$(this).find('.icon-radio').attr('data');
			if(data==1){
				$(this).find('.icon-radio').attr('data',0);
				$(this).find('.icon-radio').removeClass('checked');
			}else{
				$(this).find('.icon-radio').attr('data',1);
				$(this).find('.icon-radio').addClass('checked');
			}
		},
		questchoice_1:function(){
				$(this).parent().find('.icon-radio').removeClass('checked');
				$(this).find('.icon-radio').addClass('checked');
		},
		body_click:function(){
			//alert(123);
			//$(".popover_button").popover("hide");
			//$("body").find(".popover").remove();
			
		},
		//播放mp3
		play_mp3:function(){
			var url=$(this).attr("url");
			play_mp3(url)
		},
		
		ajax_submit:function(e){ //js提交表单
			 var xhr = e.detail.xhr; // actual XHR object
			 var data = e.detail.data; // Ajax repsonse from action file
			 var act=$(this).attr("act");
			 eval(act+"("+data+")");
			// console.log(data);
		},
		init:function(page){
			 appCtrl.bindEven();
		},
		//上传图片
		upload_input:function(e){
		  e = e || window.event;
           var fileList = e.target.files;
           if (!fileList.length) {
               return false;
           }
		 var file = fileList[0];
           if (!photo.checkPicSize(file)) {
			   hiApp.alert('图片体积过大');
           }
           if (!photo.checkPicType(file)) {
			   hiApp.alert('上传照片格式不支持');
           }

           var id = Date.now() ;
           // 增加到上传对象中, 上传完成后，修改为true
           photo.uploadInfo[id] = {
                file: file,
                filename: '',
                isDone: false,
           };
		   $('.up_pic_thumb').find('li').attr('id','li' + id);
           photo.previewQueue.push(id);
		   $(this).val('');
		},
        showToolbar: function(){
            appFunc.showToolbar();
        },
		/**********图片浏览开始呀***/
	     photoBrowser:function(){
			var url =[];
			var index = $(this).attr('index');
			var cur_img = $(this).attr('src');
			//alert(cur_img);
			var images = $(this).parent().find('img');
			for (i = 0; i < images.length; i++) {
				var img={};
				var src=images.eq(i).attr('src');
				var img_data=images.eq(i).attr('data');
				if(typeof(img_data)!="string"){
					img_data=src;
				}
				var img_title=images.eq(i).attr('alt');
				if(typeof(img_title)=="string"){
					img_title="";
				}
				img['title']=img_title;
				img['href']=img_data;
				url[i] =img;
				if(cur_img==src){
					index=i;
				}
			}
			if(!(index>0)){
				index=0;
			}
		   
			var options = {
				initialIndexOnArray : index,
			};
			$.swipebox(url,options);
	     },
		/*********图片浏览到这里结束***/ 
    };
   
 window.BoxEdu_appCtrl = appCtrl;
						
})(window);